package com.mew.chess.core.game.yxx.game.message;


import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;

@Data
@ToString
@NoArgsConstructor
public class YxxEResponseMessage extends ZebraBaseMessage<YxxEResponseMessage> {

    private YxxUserMessage userMessage;
    private int[] roomBetArray;

    //base info
    private int linkType;
    private int remainTime; // S
    private long ino;
    private YxxHistoryMessage historyVOList; // history win lose
    private List<YxxUserMessage> bigRList; // big player


    //play info
    private YxxPushBetInfoMessage betInfoMessage;
    private YxxDealCardMessage dealCardMessage;
    private YxxPaymentMessage paymentMessage;
    private long paymentNumber = -1; //当前赔付金额 （-1表示没有参与本局）

    @Override
    public void write(ByteBuf b) {

        writeMsg(b);
    }

    private void writeMsg(ByteBuf b) {
        userMessage.write(b);
        writeIntArray(b, this.roomBetArray);

        writeInt(b, this.linkType);
        writeInt(b, this.remainTime);
        writeLong(b, this.ino);

        historyVOList.writeMsg(b);

        writeInt(b, this.bigRList.size());
        for (YxxUserMessage userMessage : this.bigRList){
            userMessage.write(b);
        }
        betInfoMessage.writeMsg(b);
        dealCardMessage.writeMsg(b);
        paymentMessage.writeMsg(b);
        writeLong(b,paymentNumber);
    }

    @Override
    public YxxEResponseMessage read(ByteBuf b) {
        YxxEResponseMessage message = new YxxEResponseMessage();
        YxxUserMessage userMessage = new YxxUserMessage();
        userMessage.read(b);
        message.setUserMessage(userMessage);
        message.roomBetArray = readIntArray(b);
        message.linkType = readInt(b);
        message.remainTime = readInt(b);

        return message;
    }
}
